package com.metel.mservice.common.listener;

import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.core.io.Resource;

import com.metel.mservice.common.context.OpenAPIContext;
import com.metel.mservice.common.context.OpenAPIContextManager;

/**
 * Custom PropertyPlaceholderConfigurer
 * 
 * @author sr80.choi
 * 
 */
public class OpenAPIPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer {

	@Override
	public void setLocation(Resource location) {
		OpenAPIContext context = OpenAPIContextManager.getContext();
		Resource realResource = context.getServerPropertyLocation(location);
		
		super.setLocation(realResource);
	}

	@Override
	public void setLocations(Resource[] locations) {
		OpenAPIContext context = OpenAPIContextManager.getContext();
		
		Resource[] realResources = new Resource[locations.length];
		for(int i =0  ; i<locations.length;i++) {
			Resource currentLocation = locations[i];
			realResources[i] = context.getServerPropertyLocation(currentLocation);
		}

		super.setLocations(realResources);
	}
}
